<?php
/* @var $this UserController */
/* @var $model User */

$this->breadcrumbs=array(
	Yii::t('base','Users')=>array('admin'),
	Yii::t('base','Manage'),
);
/*$this->menu=array(
	array('label'=>'List User', 'url'=>array('index')),
	array('label'=>'Create User', 'url'=>array('create')),
);*/

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$.fn.yiiGridView.update('user-grid', {
		data: $(this).serialize()
	});
	return false;
});
");
//测试关联性 user--useservice
/*$user=User::model()->findByPk(149);
$userservice=$user->userservice;
for($i=0;$i<count($userservice);$i++){
	$result[$i]=$userservice[$i]['user_service_id'];
}*/
$level=yii::app()->request->getParam('level');
?>

<h1><?php 
	$level = $_GET['level'];
	if($level == 9){
		 echo Yii::t('base','Manage');echo Yii::t('base','Partners');
	}else if($level==12){
		echo Yii::t('base','Manage Telesales');
	}else if($level==11){
		echo Yii::t('base','Manage SalesManager');
	}else{
		echo Yii::t('base','Manage Users');
	}
?>
</h1>

<?php 
echo Yii::t('base','<p>
You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>
or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
</p>');
?>

<?php echo CHtml::link(Yii::t('base','Advanced Search'),'#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
	'model'=>$model,
)); 
?>
</div><!-- search-form -->
<?php 
if($level==4 || $level==7){
?>
<a class="btn btn-small create" title="创建代理人" href="<?php echo Yii::app()->request->baseUrl; ?>/user/createagentcompany">创建代理人</a>
<?php }elseif($level==2){?>
<a class="btn btn-small create" title="创建用户" href="<?php echo Yii::app()->request->baseUrl; ?>/user/create?level=2">创建用户</a>
<?php }elseif($level==6) {?>
<a class="btn btn-small create" title="创建销售员" href="<?php echo Yii::app()->request->baseUrl; ?>/user/create?level=6">创建销售员</a>
<?php }elseif($level==1){?>
<a class="btn btn-small create" title="创建管理员" href="<?php echo Yii::app()->request->baseUrl; ?>/user/create?level=1">创建管理员</a>
<?php }elseif($level==9){?>
<a class="btn btn-small create" title="<?php echo Yii::t('base','Create'); echo Yii::t('base','Partners');?>" href="<?php echo Yii::app()->request->baseUrl; ?>/user/create?level=9"><?php echo Yii::t('base','Create'); echo Yii::t('base','Partners');?></a>
<?php }elseif ($level==12) {?>
	<a class="btn btn-small create" title="<?php echo Yii::t('base','Create'); echo Yii::t('base','Telesales People');?>" href="<?php echo Yii::app()->request->baseUrl; ?>/user/create?level=12"><?php echo Yii::t('base','Create'); echo Yii::t('base','Telesales People');?></a>
<?php }elseif ($level==11){?>
<a class="btn btn-small create" title="<?php echo Yii::t('base','Create'); echo Yii::t('base','Sales manager');?>" href="<?php echo Yii::app()->request->baseUrl; ?>/user/create?level=11"><?php echo Yii::t('base','Create'); echo Yii::t('base','Sales manager');?></a>
<?php }?>
<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'user-grid',
	'dataProvider'=>$model->search($results),
	/*'filter'=>$model,*/
	'itemsCssClass'=>'responsive table table-striped table-bordered',
	// 'pagerCssClass'=>'pagination pull-right',
	'pager'=>array('class'=>'CLinkPager','hiddenPageCssClass'=>'','firstPageCssClass'=>'first paginate_button','htmlOptions'=>array('class'=>'dataTables_paginate paging_full_numbers"'),'header'=>""),
	'pagerCssClass'=>'pagination',
	'cssFile'=>false,
	'template'=>'{items}{summary}{pager}',
	'columns'=>array(
//	array('name'=>'user_id','headerHtmlOptions'=>array('style'=>'width:18%')),
		array('name'=>'user_name','header'=> Yii::t('base','UserName'),'headerHtmlOptions'=>array('style'=>'width:18%')),
		array('name'=>'password','headerHtmlOptions'=>array('style'=>'width:12%'),'visible'=>Yii::app()->user->level==1),
		array('name'=>'invite_code','headerHtmlOptions'=>array('style'=>'width:18%')),
	//	array('name'=>'parentId','headerHtmlOptions'=>array('style'=>'width:18%')),
		array('name'=>'telephone','headerHtmlOptions'=>array('style'=>'width:10%')),
		array('name'=>'email','headerHtmlOptions'=>array('style'=>'width:18%')),
	//	array('name'=>'userservice.equipment_number','value'=>$result[0]),
		array('name'=>'level','value'=>'User::model()->getLevelName($data->user_id)','headerHtmlOptions'=>array('style'=>'width:10%')),
	    array('name'=>'iscustomer','value'=>'User::model()->getCustomer($data->iscustomer)','visible'=>yii::app()->user->level==1),
		array('name'=>yii::t('base','Partner Type'),'value'=>'PartnerSetting::model()->PartnerType($data->partner->type)','visible'=>yii::app()->user->level==1),
	        array(
			'class'=>'CButtonColumn',
			'header'=>Yii::t('base','Operate'),
			'updateButtonImageUrl'=>array('class'=>'gicon-edit'),
			'updateButtonOptions'=>array('class'=>'btn btn-small'),
			'deleteButtonImageUrl'=>array('class'=>'gicon-edit'),
			'deleteButtonOptions'=>array('class'=>'btn btn-inverse btn-small'),
			'template'=>'{create top user}{view Agent details}{view Agent Equipment}{Reback Staff Equipment}{Distribution staff Equipment}{Reback Agent Equipment}{create sub user}{view Equipment}{view AgentPerson details}{Recharge}{update}{Distribution service}{Distribution Equipment}{Reback Equipment}{Distribution Agent Equipment}{Create staff agent}{delete}{Binding Credit Card}{create prize users}{Equipment Distribution}',
			'buttons'=>array(
					'Distribution Equipment'=>array(
							'label'=>Yii::t('base','Distribution Equipment'),
							'url'=>'Yii::app()->createUrl("userService/Distribution",array("user_id"=>$data->user_id))',
							'options'=>array('class'=>'btn btn-small'),
							'visible'=>'yii::app()->request->getParam("level")==6'
					),
					'Distribution staff Equipment'=>array(
							'label'=>Yii::t('base','Distribution Equipment'),
							'url'=>'Yii::app()->createUrl("userService/StaffDistribution",array("user_id"=>$data->user_id))',
							'options'=>array('class'=>'btn btn-small'),
							'visible'=>'yii::app()->user->level==4 && User::model()->getlevel($data->user_id)==5'
					),
					'view Agent details'=>array(
							'label'=>Yii::t('base','view Agent details'),
							'url'=>'Yii::app()->createUrl("agentCompany/view",array("id"=>AgentCompany::model()->find("user_id=".$data->user_id)->agent_id))',
							'options'=>array('class'=>'btn btn-small'),
							'visible'=>'yii::app()->request->getParam("level")==4 || yii::app()->request->getParam("level")==7 || (yii::app()->request->getParam("level")=="" && yii::app()->user->level==4) || yii::app()->user->level==7'
					),
					'view Agent Equipment'=>array(
							'label'=>Yii::t('base','view Equipment'),
							'url'=>'Yii::app()->createUrl("equipment/viewagentequipment",array("user_id"=>$data->user_id))',
							'options'=>array('class'=>'btn btn-small'),
							'visible'=>'(yii::app()->request->getParam("level")==4 || yii::app()->request->getParam("level")==7 || yii::app()->request->getParam("level")==5 || yii::app()->user->level==7)  && User::model()->isagenthaveEquipment($data->user_id)!=""'
					),
					'view AgentPerson details'=>array(
							'label'=>Yii::t('base','view AgentPerson details'),
							'url'=>'Yii::app()->createUrl("agentPerson/view",array("id"=>AgentPerson::model()->find("user_id=".$data->user_id)->agent_person_id))',
							'options'=>array('class'=>'btn btn-small'),
							'visible'=>'yii::app()->request->getParam("level")==5'
					),
					'Distribution Agent Equipment'=>array(
							'label'=>Yii::t('base','Distribution Equipment'),
							'url'=>'Yii::app()->createUrl("userService/AgentDistribution",array("user_id"=>$data->user_id))',
							'options'=>array('class'=>'btn btn-small'),
							'visible'=>'(yii::app()->request->getParam("level")==4 && yii::app()->user->level==1) || (yii::app()->request->getParam("level")==5 && yii::app()->user->level==1 )|| (yii::app()->request->getParam("level")==7 && yii::app()->user->level==1)'
					),
					'Reback Equipment'=>array(
							'label'=>Yii::t('base','Reback Equipment'),
							'url'=>'Yii::app()->createUrl("userService/Reback",array("user_id"=>$data->user_id))',
							'options'=>array('class'=>'btn btn-small'),
							'visible'=>'(yii::app()->request->getParam("level")==6 || yii::app()->user->level==6)  && User::model()->ishaveEquipment($data->user_id)!=""'
					),
					'Reback Agent Equipment'=>array(
							'label'=>Yii::t('base','Reback Equipment'),
							'url'=>'Yii::app()->createUrl("userService/Reback2",array("user_id"=>$data->user_id))',
							'options'=>array('class'=>'btn btn-small'),
							'visible'=>'(yii::app()->request->getParam("level")==4 || yii::app()->request->getParam("level")==7)  && User::model()->isagenthaveEquipment($data->user_id)!=""'
					),
					'Reback Staff Equipment'=>array(
							'label'=>Yii::t('base','Reback Equipment'),
							'url'=>'Yii::app()->createUrl("userService/Reback3",array("user_id"=>$data->user_id))',
							'options'=>array('class'=>'btn btn-small'),
							'visible'=>'yii::app()->request->getParam("level")==5  && User::model()->getlevel($data->user_id)==5  && User::model()->isagenthaveEquipment($data->user_id)!=""'
					),
					'view Equipment'=>array(
							'label'=>Yii::t('base','view Equipment'),
							'url'=>'Yii::app()->createUrl("equipment/viewequipment",array("user_id"=>$data->user_id))',
							'options'=>array('class'=>'btn btn-small'),
							'visible'=>'(yii::app()->request->getParam("level")==6 || yii::app()->user->level==6)  && User::model()->ishaveEquipment($data->user_id)!=""'
					),
					'Recharge'=>array(
							'label'=>Yii::t('base','Recharge'),
							'url'=>'Yii::app()->createUrl("AgentRecharge/create",array("user_id"=>$data->user_id,"level"=>yii::app()->request->getParam("level")))',
							'options'=>array('class'=>'btn btn-small'),
							'visible'=>'yii::app()->request->getParam("level")==4 || yii::app()->request->getParam("level")==5 || yii::app()->request->getParam("level")==7'
					),
						
				'create top user'=>array(
					'label'=>Yii::t('base','Create total account'),
					'options'=>array('class'=>'btn btn-small'),
					'url'=>'Yii::app()->createUrl("user/create",array("level"=>2))',
					'visible'=>'Yii::app()->request->getParam("level")==1',
				),
				'create sub user'=>array(
					'label'=>Yii::t('base','Create child users'),
					'options'=>array('class'=>'btn btn-small'),
					'url'=>'Yii::app()->createUrl("user/create",array("level"=>3,"user_id"=>$data->user_id))',
					'visible'=>'yii::app()->user->level==2 && $data->level==2',
				),
				'Distribution service'=>array(
					'label'=>Yii::t('base','Distribution service'),
					'url'=>'Yii::app()->createUrl("userService/create",array("user_id"=>$data->user_id))',
					'options'=>array('class'=>'btn btn-small'),
					'visible'=>'(Yii::app()->user->level==1 && $data->level==2)||(Yii::app()->user->level==2&&$data->level==3)'
				),	
				'Create staff agent'=>array(
					'label'=>Yii::t('base','Create staff agent'),
					'url'=>'Yii::app()->createUrl("user/createagentperson",array("agent_number"=>AgentCompany::model()->find("user_id=".$data->user_id)->agent_number,"user_id"=>$data->user_id))',
					'options'=>array('class'=>'btn btn-small'),
					'visible'=>'yii::app()->user->level==4 && yii::app()->request->getParam(level)==4',
				),
				'Binding Credit Card'=>array(
					'label'=>Yii::t('base','Binding Credit Card'),
					'url'=>'Yii::app()->createUrl("cardInfo/create",array("user_id"=>$data->user_id,"level"=>yii::app()->request->getParam("level")))',
					'options'=>array('class'=>'btn btn-small'),
					'visible'=>'yii::app()->user->level==2 || yii::app()->user->level==3 || yii::app()->user->level==4 || yii::app()->user->level==7',
				),
				'create prize users'=>array(
					'label'=>Yii::t('base','Create prize users'),
					'options'=>array('class'=>'btn btn-small'),
					'url'=>'Yii::app()->createUrl("user/create",array("level"=>10,"user_id"=>$data->user_id))',
					'visible'=>'yii::app()->user->level==9',
				),
				'Equipment Distribution'=>array(//这个已废除
					'label'=>Yii::t('base','Equipment Distribution'),
					'options'=>array('class'=>'btn btn-small'),
					'url'=>'Yii::app()->createUrl("distributionGiftNumber/create",array("user_id"=>$data->user_id))',
					'visible'=>'yii::app()->user->level==10000',
				),
			),
			 'headerHtmlOptions'=>array('style'=>'width:34%'),
		),
		
	),
)); ?>
